package de.rts.components;

import java.awt.Point;

public class Sensor implements RailComponent
{

  private Point[]    position;
  private String     sensorId;
  private SensorType type = SensorType.NONE;

  public Sensor(String id)
  {
    this(new Point[]
    {}, SensorType.NONE, id);
  }

  public Sensor(Point[] position, String id)
  {
    this(position, SensorType.NONE, id);
  }

  public Sensor(Point[] position, SensorType type, String id)
  {
    super();
    try
    {
      if (position == null) throw new RailwayComponentException("Initialization error");
    }
    catch (RailwayComponentException e)
    {
      e.printStackTrace();
    }
    this.position = position;
    this.sensorId = id;
    this.type = type;
  }

  public Point[] getPosition()
  {
    return position;
  }

  public void setPosition(Point[] position)
  {
    this.position = position;
  }

  public String getSensorId()
  {
    return sensorId;
  }

  public SensorType getType()
  {
    return type;
  }

  public void setType(SensorType type)
  {
    this.type = type;
  }

  public int[] getXPositions()
  {
    int[] xpos = new int[position.length];
    for (int i = 0; i < position.length; i++)
      xpos[i] = position[i].x;
    return xpos;
  }

  public int[] getYPositions()
  {
    int[] ypos = new int[position.length];
    for (int i = 0; i < position.length; i++)
      ypos[i] = position[i].y;
    return ypos;
  }

  @Override
  public String toString()
  {
    return "Sensor@" + hashCode() + "[sensorId=" + sensorId + ", type=" + type + "]";
  }
}
